package com.docMan.service.impl;

import java.sql.Timestamp;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.docMan.dao.BaseDao;
import com.docMan.dao.pojo.DocFile;
import com.docMan.dao.pojo.DocRecord;
import com.docMan.service.DocFileService;
import com.docMan.service.DocRecordService;
import com.docMan.utils.FinalConfig;

@Service("docRecordService")
public class DocRecordServiceImpl extends BaseServiceImpl<DocRecord> implements DocRecordService {
	private HttpSession session;
	private DocFileService docFileService;
	@Autowired
	public void setDocFileService(DocFileService docFileService) {
		this.docFileService = docFileService;
	}

	@Autowired
	public void setSession(HttpSession session) {
		this.session = session;
	}

	@Resource
	@Override
	public void setDao(BaseDao<DocRecord> dao) {
		// TODO Auto-generated method stub
		super.setDao(dao);
	}

	@Override
	public void record(int fileId,String type) {
		DocRecord docRecord=new DocRecord();
		docRecord.setFileId(fileId);
		if(null==session.getAttribute(FinalConfig.SESSION_HUMANID)){
			
		}else {
			docRecord.setHumanId((int)session.getAttribute(FinalConfig.SESSION_HUMANID));
			docRecord.setHumanName((String)session.getAttribute(FinalConfig.SESSION_HUMANNAME));
		}
		docRecord.setCreateTime(new Timestamp(System.currentTimeMillis()));
		docRecord.setType(type);
		save(docRecord);
	}

	@Override
	public String getRecord(int fileId) {
		List<DocRecord> list=find("select r from DocRecord r where r.fileId=? order by r.createTime desc", fileId);
		DocFile docFile=docFileService.getById(fileId);
		put("records", list);
		put("file", docFile);
		putSuccess();
		return getMap();
	}

	
}
